package com.ruoyi.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizLogMq;
import com.ruoyi.system.service.IBizLogMqService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务数据审计Controller
 * 
 * @author ruoyi
 * @date 2019-08-26
 */
@Controller
@RequestMapping("/system/mq")
public class BizLogMqController extends BaseController
{
    private String prefix = "system/mq";

    @Autowired
    private IBizLogMqService bizLogMqService;

    /*@Lazy
    @Autowired
    @Qualifier("com.ruoyi.mq.kafka.KafkaProducer")
    private KafkaProducer mqPro ;*/

    @RequiresPermissions("system:mq:view")
    @GetMapping()
    public String mq()
    {
        return prefix + "/mq";
    }

    /**
     * 查询业务数据审计列表
     */
    @RequiresPermissions("system:mq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizLogMq bizLogMq)
    {
        startPage();
        List<BizLogMq> list = bizLogMqService.selectBizLogMqList(bizLogMq);
        return getDataTable(list);
    }

    /**
     * 导出业务数据审计列表
     */
    @RequiresPermissions("system:mq:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizLogMq bizLogMq)
    {
        List<BizLogMq> list = bizLogMqService.selectBizLogMqList(bizLogMq);
        ExcelUtil<BizLogMq> util = new ExcelUtil<BizLogMq>(BizLogMq.class);
        return util.exportExcel(list, "mq");
    }

    /**
     * 新增业务数据审计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业务数据审计
     */
    @RequiresPermissions("system:mq:add")
    @Log(title = "业务数据审计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizLogMq bizLogMq)
    {
        return toAjax(bizLogMqService.insertBizLogMq(bizLogMq));
    }

    /**
     * 修改业务数据审计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BizLogMq bizLogMq = bizLogMqService.selectBizLogMqById(id);
        mmap.put("bizLogMq", bizLogMq);
        return prefix + "/edit";
    }

    /**
     * 修改保存业务数据审计
     */
    @RequiresPermissions("system:mq:edit")
    @Log(title = "业务数据审计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizLogMq bizLogMq)
    {
        return toAjax(bizLogMqService.updateBizLogMq(bizLogMq));
    }

    /**
     * 删除业务数据审计
     */
    @RequiresPermissions("system:mq:remove")
    @Log(title = "业务数据审计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizLogMqService.deleteBizLogMqByIds(ids));
    }

    @Log(title = "发送MQ消息", businessType = BusinessType.OTHER)
    @PostMapping("/sendmq")
    @ResponseBody
    public AjaxResult sendMQ(String msg){
        logger.info("==msg=={}",msg);
        //mqPro.send(msg);

        return AjaxResult.success();
    }
}
